<?php
include("config.php");
ini_set("display_errors", 1); 
//$insert = new RequeteInsert();
$Upload = new Upload();
function pArray($array) {
	print '<pre style="background:#faebd7">';
	print_r($array);
	print '</pre>';
}
require_once('recaptchalib.php');

// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "6LczgN0SAAAAAAZ49I0PP9i1jE7VdNixRCdWOwry";
$privatekey = "6LczgN0SAAAAAIt9V9q7mj44p1j5bx49ixae-qU7";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if (!Empty($_POST['submit'])) {

    if(isset($_POST['nom'])&!empty($_POST['nom'])){
		$nom = $_POST['nom'];
	}
	else{ $nom ='';}
	
	if(isset($_POST['prenom'])&!empty($_POST['prenom'])){
		$prenom = $_POST['prenom'];
	}
	else{ $prenom ='';}
	echo $prenom;
	if(isset($_POST['email'])&!empty($_POST['email'])){
		$email= $_POST['email'];
	}
	else{ $email ='';}
	if(isset($_POST['cp'])&!empty($_POST['cp'])){
		$cp= $_POST['cp'];
	}
	else{ $cp ='';}
	
		if ($_POST["recaptcha_response_field"]) {
				$resp = recaptcha_check_answer ($privatekey,
												$_SERVER["REMOTE_ADDR"],
												$_POST["recaptcha_challenge_field"],
												$_POST["recaptcha_response_field"]);

								   

			
			/*if (!$resp->is_valid) {
						?>
						<script type='text/javascript'>
						 // window.location="/?page_id=4&error=saissie incorecte&nom=<?php echo $nom ?>&prenom=<?php echo $prenom ?>&email=<?php echo $email ?>&cp=<?php echo $cp ?>";
					   </script>
					   <?php
			} else {*/
			//$repertoire = $insert->InsertPhoto($nom,$prenom,$email,$cp);
			
			$wpdb->insert('wp_galerie', array('nom'=>$nom,'prenom'=>$prenom,'email'=>$email,'cp'=>$cp, 'date_poste'=>current_time('mysql',0)), array('%s','%s') );
			$repertoire = $wpdb->insert_id;
			echo $repertoire;
			var_dump(is_dir('/wp-content/photos/'));
			echo getcwd();
			mkdir('C:\xampp\htdocs\projet-lpst-wp\wp-content\photos\\'.$repertoire, 0777);
			
			$Upload-> DirUpload = 'C:\xampp\htdocs\projet-lpst-wp\wp-content\photos\\'.$repertoire;
			if (!$Upload->Execute()) {
				print 'Il y a eu une erreur :'; 
				pArray($Upload-> GetError());
				print '<a href="galerie_photos.php">Retourner au formulaire</a>';
				exit;
			}
		   

			
			

						$headers = "Reply-To : contact@tousarbitres.fr\n";
						$headers = "From: tousarbitres<contact@tousarbitres.fr>\n";
						$headers .= "Bcc:Nicolas<ng@asdepique.com>\n";
						
						$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
						$headers .= "Content-transfer-encoding: 7BIT\n\n";
						
						$body="<font color='#000000;' face='Century Gothic, Gill sans MT,Verdana' size='2'>";
						
						$body.="Une nouvelle photo a été envoyée par un postier arbitre.<br>";
						$body.="<a href='http://www.tousarbitres/admin'>";
						$body.="http://www.tousarbitres/admin";
						$body.="</a>";
						$body.="<br><br>";
						$body.="</font>";
						$obj="Nouvelle photo envoyée sur Tousarbitres";
						
						$dest = 'gbenounicolas@gmail.com';
						mail($dest,$obj,$body,$headers);?>
						<script type='text/javascript'>
						  //window.location="reponse_formulaire_photos.php";
					   </script>
		<?php  exit;/*} */
		  }
		  else{?>
				<script type='text/javascript'>
				  //window.location="/?page_id=4&error=saissie incorecte&nom=<?php echo $nom ?>&prenom=<?php echo $prenom ?>&email=<?php echo $email ?>&cp=<?php echo $cp ?>";
			    </script>
		<?php
		  }
 }
?>
    
    
    